| Conditions | 1 |
| Paths | 24 |
| Total Lines | 121 |
| Code Lines | 94 |
| Lines | 0 |
| Ratio | 0 % |
| Changes | 12 | ||
| Bugs | 0 | Features | 0 |
Small methods make your code easier to understand, in particular if combined with a good name. Besides, if your method is small, finding a good name is usually much easier.
For example, if you find yourself adding comments to a method's body, this is usually a good sign to extract the commented part to a new method, and use the comment as a starting point when coming up with a good name for this new method.
Commonly applied refactorings include:
If many parameters/temporary variables are present:
| 1 | var TableInitSetColumnsHoverEffect = function(tContainer, tableId){ |
||
| 232 | function initInstance(){ |
||
| 233 | // Singleton |
||
| 234 | // Private methods and variables |
||
| 235 | var tail = null; |
||
| 236 | var BuildRequest = function(rq, crntTableId, strDesc){ |
||
| 237 | rq.tableId = crntTableId; |
||
| 238 | TableHelperBuildRequest.Sort(rq, strDesc); |
||
| 239 | TableHelperBuildRequest.Filter(rq); |
||
| 240 | }; |
||
| 241 | function LoadData(tableContainer, rq){ |
||
| 242 | if(tail!==null){ tail.abort();} |
||
| 243 | TableHelperSetVisability(tableContainer, false); |
||
| 244 | var xmlhttp = window.XMLHttpRequest ? |
||
| 245 | new XMLHttpRequest() : /* code for IE7+, Firefox, Chrome, Opera, Safari */ |
||
| 246 | new window.ActiveXObject("Microsoft.XMLHTTP");/*code for IE6, IE5 */ |
||
| 247 | xmlhttp.onreadystatechange = function(){ |
||
| 248 | if(xmlhttp.readyState === 4 && xmlhttp.status === 200){ |
||
| 249 | Draw(tableContainer, JSON.parse(xmlhttp.responseText)); |
||
| 250 | TableHelperSetVisability(tableContainer, true); |
||
| 251 | instance.LoadEndCalback(tableContainer); |
||
| 252 | } |
||
| 253 | }; |
||
| 254 | xmlhttp.open("GET", RequestToUrl(rq), true); |
||
| 255 | xmlhttp.send(); |
||
| 256 | tail = xmlhttp; //put at tail to can abort later any previous |
||
| 257 | } |
||
| 258 | function Init(tableId){ |
||
| 259 | var tContainer = document.getElementById(tableId); |
||
| 260 | if(iePrior(9)){ |
||
| 261 | TableInitSetColumnsHoverEffect(tContainer, tableId); |
||
| 262 | } |
||
| 263 | var tfoot = tContainer.getElementsByTagName("tfoot")[0]; |
||
| 264 | TableHelperProcessPaginationLinks(tfoot); |
||
| 265 | } |
||
| 266 | function Draw(tableContainer, d){ |
||
| 267 | TableHelperDraw_Section(tableContainer, d.body); |
||
| 268 | TableHelperDraw_Section(tableContainer, d.footer, "tfoot"); |
||
| 269 | if(instance.rq !== null){ |
||
| 270 | var hover = document.getElementById(instance.rq.tableId) |
||
| 271 | .getElementsByTagName("th")[instance.rq.colNo].lang; |
||
| 272 | if(hover){ |
||
| 273 | instance.ColumnHover(tableContainer, instance.rq.colNo); |
||
| 274 | } |
||
| 275 | } |
||
| 276 | } |
||
| 277 | |||
| 278 | var FilterGetTableId = TableHelperFilterGetTableId; |
||
| 279 | var GoPageGetNo = TableHelperGoPageGetNo; |
||
| 280 | var getParent = TableHelperGetParent; |
||
| 281 | var iePrior = TableHelperIePrior; |
||
| 282 | var RequestToUrl = TableHelperRequestToUrl; |
||
| 283 | |||
| 284 | return { |
||
| 285 | rq: null, |
||
| 286 | strAsc: String.fromCharCode(9650), //▲ |
||
| 287 | strDesc: String.fromCharCode(9660),//▼ |
||
| 288 | ReloadData: function(tableId){ |
||
| 289 | var request = {}; |
||
| 290 | BuildRequest(request, tableId, this.strDesc); |
||
| 291 | LoadData(tableId, request); |
||
| 292 | }, |
||
| 293 | Filter: function(field){ |
||
| 294 | var crntTableId = FilterGetTableId(field); |
||
| 295 | if(crntTableId !== null){ |
||
| 296 | var request = {}; |
||
| 297 | var exRq = this.rq; |
||
| 298 | BuildRequest(request, crntTableId, this.strDesc); |
||
| 299 | if(exRq === null || |
||
| 300 | request.filter !== exRq.filter || |
||
| 301 | request.filterBy !== exRq.filterBy |
||
| 302 | ){ |
||
| 303 | LoadData(crntTableId, request); |
||
| 304 | } |
||
| 305 | } |
||
| 306 | }, |
||
| 307 | GoPage: function(lnk){ |
||
| 308 | var request = {}; |
||
| 309 | var crntTableId = getParent(lnk, "table").getAttribute("id"); |
||
| 310 | BuildRequest(request, crntTableId, this.strDesc); |
||
| 311 | request.pageNo = GoPageGetNo(lnk, crntTableId); |
||
| 312 | LoadData(crntTableId, request); |
||
| 313 | return false; |
||
| 314 | }, |
||
| 315 | Export: function(lnk, eType){ |
||
| 316 | var request = {}; |
||
| 317 | var crntTableId = getParent(lnk, "table").getAttribute("id"); |
||
| 318 | BuildRequest(request, crntTableId, this.strDesc); |
||
| 319 | request.exportType = ["CSV", "Excel"].indexOf(eType) >= 0 ? |
||
| 320 | eType : |
||
| 321 | "csv"; |
||
| 322 | window.open(RequestToUrl(request)); |
||
| 323 | return false; |
||
| 324 | }, |
||
| 325 | Sort: function(colNo, lnk){ |
||
| 326 | var request = {}; |
||
| 327 | var crntTableId = getParent(lnk, "table").getAttribute("id"); |
||
| 328 | BuildRequest(request, crntTableId, this.strDesc); |
||
| 329 | if(Math.round(colNo) === request.colNo){ |
||
| 330 | request.colOrd = (request.colOrd === "asc" ? "desc" : "asc"); |
||
| 331 | }else{ |
||
| 332 | request.colNo = Math.round(colNo); |
||
| 333 | request.colOrd = "asc"; |
||
| 334 | } |
||
| 335 | LoadData(crntTableId, request); |
||
| 336 | /* Clear and add new sort arrow */ |
||
| 337 | var headSpans = getParent(lnk, "thead").getElementsByTagName("span"); |
||
| 338 | var length = headSpans.length; |
||
| 339 | for(var i = 0; i < length; i++){ |
||
| 340 | headSpans[i].innerHTML = ""; |
||
| 341 | } |
||
| 342 | lnk.getElementsByTagName("span")[0].innerHTML = (request.colOrd === "desc" ? this.strDesc : this.strAsc); |
||
| 343 | }, |
||
| 344 | ColumnHover: function(tableContainer, index){ |
||
| 345 | if(!iePrior(9)){ |
||
| 346 | TableHelperColumnHover.call(this, tableContainer, index); |
||
| 347 | } |
||
| 348 | }, |
||
| 349 | LoadEndCalback: function(){},/*Allows override: function(tableId){if(tableId){...}}*/ |
||
| 350 | init: Init |
||
| 351 | }; |
||
| 352 | } |
||
| 353 | return { |
||
| 364 |
When iterating over the keys of an object, this includes not only the keys of the object, but also keys contained in the prototype of that object. It is generally a best practice to check for these keys specifically: